Mule : Writing Components
This page last changed on May 31, 2006 by tcarlson.
As components in Mule can be plain old objects it's not always clear to the newcomer how Mule will interact with their component. Entry PointsThe entry point is the method executed by Mule when an event is received for the component. When an event is received for your component Mule dynamically chooses the method to invoke based on the payload type of the event. This means potentially your component may have many entry points. The payload type of the event is almost always determined by the inbound transformer for the provider that recieved the event for your component, but some providers such as the soap provider manage type mappings themselves so there are no need for transformers. If your component implements the Mule default event interface org.mule.umo.lifecycle.Callable this will always be called. Event FlowMule has some default behavior rules about managing event flow to and from your component.
Customizing BehaviorWhile the default event flow behavior is sufficient, in most cases you may at some point want to customize it. To do this, you need to get a reference to the org.mule.umo.UMOEventContext. This can be done in two ways - Implement org.mule.umo.lifecycle.Callable. The event context is passed as a parameter on this interface. public interface Callable { public Object onCall(UMOEventContext eventContext) throws Exception; } You can also obtain the EventContext from the static RequestContext - UMOEventContext context = RequestContext.getEventContext(); From the EventContext you can send and receive events synchronously and asynchronously, manage transactions and override the default event flow behavior. For example - UMOEventContext context = RequestContext.getEventContext(); UMOEndpoint endpoint = new MuleEndpoint("jms://localhost/topic:stock.quotes"); //to send asynchronously context.dispatchEvent(new MuleMessage("IBM:0.01", null), endpoint); //or to receive UMOMessage quote = context.receive(endpoint, 5000); Even when you use the event context to manually control event flow, when your method returns, Mule will route the outbound event as normal. You can stop Mule processing events further using the following 2 methods. 1. If your service method is not void you can return null. This tells Mule there is no further event information to process. 2. If your service method is void, Mule will use the inbound event payload as the outbound event payload. If you don't want this to happen, you need to make the following call- context.setStopFurtherProcessing(true);
Component LifecycleYour component can implement zero or more lifecycle interfaces, namely -
Getting the components DescriptorA component can get a reference to its descriptor on startup by implementing org.mule.impl.UMODescriptorAware. The UMODescriptor holds all configuration information about a component. |
Document generated by Confluence on Nov 27, 2006 10:27 |